<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
	template="/WEB-INF/templates/default.xhtml" xmlns:s="http://jboss.com/products/seam/taglib">
	<ui:define name="content">
		<h3>Maintenances</h3>

		<h:form>
			<h5>
				<h:outputText value="#{vehicleController.vehicle.vehicleModel.vehicleMake.makeName} #{vehicleController.vehicle.vehicleModel.modelName} " />
				<h:outputText value="VIN : #{vehicleController.vehicle.vin}" />
			</h5>
			<h:panelGroup rendered="#{empty vehicleController.maintenances}">
				<em>No maintenance </em>
			</h:panelGroup>
			<h:dataTable var="_maintenance" value="#{vehicleController.maintenances}" rendered="#{not empty vehicleController.maintenances}" styleClass="simpletablestyle">
				<h:column>
					<f:facet name="header">Date</f:facet>
               		 #{_maintenance.date}
            	</h:column>
				<h:column>
					<f:facet name="header">Odometer</f:facet>
              		#{_maintenance.odometer}
           		</h:column>
				<h:column>
					<f:facet name="header">Maintenance Task</f:facet>
					<h:outputText value="#{_maintenance.maintenanceTask}" />
				</h:column>
				<h:column rendered="#{login.admin}">
					<f:facet name="header">action</f:facet>
					<h:commandButton action="#{vehicleController.editMaintenance(_maintenance)}" value="Edit" />
					<h:commandButton action="#{vehicleController.deleteMaintenance(_maintenance)}" value="Delete" />
				</h:column>
			</h:dataTable>
			<br />
			<h:commandButton rendered="#{login.admin}" action="#{vehicleController.newMaintenance}" value="New maintenance" />
			<h:form id="newMaintenance" rendered="#{not empty newMaintenance}">
				<h:panelGrid columns="2">
					<h:outputText value="Odometer :" />
					<h:inputText value="#{vehicleController.newMaintenance.odometer}" />
					<h:outputText value="Maintenance task :" />
					<h:inputText value="#{vehicleController.newMaintenance.maintenanceTask}" />
				</h:panelGrid>
				<div style="float: right;">
					<h:commandButton action="#{vehicleController.saveMaintenance}" value="Save" rendered="#{newMaintenance.maintenanceId == 0}" />
					<h:commandButton action="#{vehicleController.editMaintenance}" value="Save changes" rendered="#{newMaintenance.maintenanceId != 0}" />
					<h:commandButton action="#{vehicleController.cancelMaintenance}" value="Cancel" />
				</div>
			</h:form>
		</h:form>
			<h:form>
				<h:commandLink action="#{login.logout()}" value="Logout" />
			</h:form>

	</ui:define>
</ui:composition>
